/*
 * @Description:
 * @Version: 2.0
 * @Autor: wsh
 * @Date: 2023-06-20 16:06:20
 * @LastEditors: uphldjx 1373577124@qq.com
 * @LastEditTime: 2024-04-23 17:30:13
 */
import { getBaseAreaData } from '@/utils/util'
import { getStore } from '@/utils/store'

let typeList = [
	{label:"基础类项目",value:"0",type:"primary"},
	{label:"可选类项目",value:"1",type:"primary"}
]
// 列表
const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{ label: '改造类别', prop: 'reformType',custome:'tag',dicData:typeList },
		{ label: '改造设备名称', prop: 'deviceName' },
		{ label: '设备安装费用（元）', prop: 'amount'},
		{
			label: '设备安装数量（个）',
			prop: 'count',
		},
		{
			label: '改造前图片',
			custome:'img',
			prop: 'reformPic',
		},
		{ label: '设备改造后图片',custome:'img', prop: 'reformPicAfter' },
		{ label: '备注', prop: 'remark' },
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}
export const formConfig =  {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	column:[
		{
			label:"改造类别",
			prop:"reformType",
			propName:"reformTypeLabel",
			type:"select",
			dicData:typeList,
			span:12,
			rules:[
				{required:true,message:"请填写改造类别"}
			]
		},
		{
			label:"改造设备名称",
			prop:"deviceName",
			span:12,
			rules:[
				{required:true,message:"请填写改造设备名称"}
			]
		},
		{
			label:"设备安装费用（元）",
			prop:"amount",
			span:12,
			rules:[
				{required:true,message:"请填写设备安装费用（元）"}
			]
		},
		{
			label:"设备安装数量（个）",
			prop:"count",
			span:12,
			rules:[
				{required:true,message:"请填写设备安装费用（个）"}
			]
		},
		{
			label:"改造前照片",
			type:'upload',
			// apiName: 'ost_uploadFile2',
			fileType:'image/png,image/jpg,image/jpeg',
			accept:'.png,.jpg,.jpeg',
			listType: 'picture-card',
			labelPosition: 'top',
			showFileList: true,
			multiple: true,
			prop:"reformPic",
			uploadTip:"上传文件（图片）",
			span:12,
			rules:[
				{required:true,message:"请填写改造前照片"}
			]
		},
		{
			label:"改造后照片",
			type:'upload',
			// apiName: 'ost_uploadFile2',
			prop:"reformPicAfter",
			fileType:'image/png,image/jpg,image/jpeg',
			accept:'.png,.jpg,.jpeg',
			listType: 'picture-card',
			labelPosition: 'top',
			showFileList: true,
			multiple: true,
			uploadTip:"上传文件（图片）",
			span:24,
			rules:[
				{required:true,message:"请填写改造后照片"}
			]
		},
		{
			label:"备注",
			type:"textarea",
			prop:"remark",
			span:24,
			rules:[
				{required:true,message:"请填写备注"}
			]
		}
	]
}


export const api = {
	index: 'view_bscAdaptDevice_page',
	detail:"view_bscAdaptDevice_view",
	
}

export const baseConfig = {
	pageName: '适老化改造实施管理',
	// 数据字典
	dictcodes: [],
	rowKey: 'id',
	tipLabel: 'deviceName',
	addLabel: '新增',
	api: {
		...api,
	},
	auth: {
		...api,
	},

	// 当前行操作按钮
	menuBtn: [
		{
			label: '详情',
			type: 'primary',
			operate: 'detail',
			auth: api.index,
			text: true,
			show: true,
		}
	],
	dialogConfig: {
		width: '80%',
	},
	formConfig,
	detailConfig:formConfig,
	// 列表
	tableConfig,
    saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			resolve(form)
		})
	},
	onLoadFormate: async (arr) => {
		let tableData = arr.map((item) => {
           // 处理编辑和删除控制
			let userInfo = getStore('userInfo')
			if(userInfo.classifyId==3){
				// 行政用户，用区域判断
				if(getBaseAreaData(item).myAreaId==getBaseAreaData(userInfo).myAreaId&&item.authOrganizationId==userInfo.organizationId){
					item.isEditDel = true
				}else{
					item.isEditDel = false
				}
			}else if(userInfo.classifyId==5){
				// 服务商
				if(item.authOrganizationId==userInfo.organizationId){
					item.isEditDel = true
				}else{
					item.isEditDel = false
				}
			}
			return item
		})
		return Promise.resolve(tableData)
	},
	beforeOnLoadFormate(form) {
		return new Promise((resolve, reject) => {
			resolve(form)
		})
	},
}
